package com.example.tvmatchddemo;

import android.os.Bundle;


import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.example.tvmatchddemo.base.PagerFragmentAdapter;
import com.example.tvmatchddemo.custom.TvTabLayout;
import com.example.tvmatchddemo.fragment.MessageFragment;
import com.example.tvmatchddemo.fragment.MusicFragment;
import com.example.tvmatchddemo.fragment.PhotoFragment;
import com.example.tvmatchddemo.fragment.SettingFragment;
import com.example.tvmatchddemo.fragment.VideoFragment;
import com.example.tvmatchddemo.fragment.WoxiuFragment;

import java.util.ArrayList;
import java.util.List;

public class Homectivity extends AppCompatActivity {
    private static final String TAG = Homectivity.class.getSimpleName();
    private TvTabLayout mTabLayout;
    private List<String> list;
    private ViewPager2 viewPager;
    private List<Fragment> fragments;
    private PagerFragmentAdapter pagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        mTabLayout = findViewById(R.id.tablayout);
        viewPager = findViewById(R.id.view_page);
        iniData();
        ininView();
    }
    private void iniData() {
        list = new ArrayList<>();
        list.add("我秀沃家");
        list.add("相册");
        list.add("音乐");
        list.add("影视");
        list.add("消息");
        list.add("设置");
        fragments = new ArrayList<>();
        fragments.add(new WoxiuFragment());
        fragments.add(new PhotoFragment());
        fragments.add(new MusicFragment());
        fragments.add(new VideoFragment());
        fragments.add(new MessageFragment());
        fragments.add(new SettingFragment());
    }

    private void ininView() {
        // 代码动态添加tab
        for (int i = 0; i < list.size(); i++) {
            if (i == 0) {
                mTabLayout.addTab(mTabLayout.newTab().setText(list.get(i)), true);
            } else {
                mTabLayout.addTab(mTabLayout.newTab().setText(list.get(i)),false);
            }
        }
//        pagerAdapter = new PagerFragmentAdapter(getSupportFragmentManager(), fragments, list);
//        viewPager.setAdapter(pagerAdapter);
//        //这个是可以viewpager滑动的，上面指示器也可以滑动
//        mTabLayout.setupWithViewPager(viewPager);
    }

}
